<script setup lang="ts">
defineOptions({name:'Category'})
import {onMounted} from "vue";
import useCategoryStore from '@/store/modules/category.ts'
const categoryStore = useCategoryStore()
defineProps(['scene'])
/**
 * 获取一级分类
 */
const getC1 = async () => {
   await categoryStore.getC1()
}
onMounted(()=>{
  getC1()
})
/**
 * 选择一级触发
 */
const handler1 = () => {
  categoryStore.c2Id=''
  categoryStore.c3Arr=[]
  categoryStore.c3Id=''
  categoryStore.getC2()
}
/**
 * 选择二级触发
 */
const handler2 = () => {
  categoryStore.c3Id=''
  categoryStore.getC3()
}
/**
 * 选择三级触发
 */
const handler3 = () => {
  categoryStore.getC3()
}
</script>

<template>
  <el-card>
    <el-form :inline="true">
      <el-form-item label="一级分类">
        <el-select placeholder="请选择" v-model="categoryStore.c1Id" @change="handler1" :disabled="scene!=0">
          <el-option :label="item.name" v-for="item in categoryStore.c1Arr" :key="item.id" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="二级分类">
        <el-select placeholder="请选择" v-model="categoryStore.c2Id" @change="handler2" :disabled="scene!=0">
          <el-option :label="item.name" v-for="item in categoryStore.c2Arr" :key="item.id" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="三级分类" >
        <el-select placeholder="请选择" v-model="categoryStore.c3Id" @change="handler3" :disabled="scene!=0">
          <el-option :label="item.name" v-for="item in categoryStore.c3Arr" :key="item.id" :value="item.id"></el-option>
        </el-select>
      </el-form-item>
    </el-form>
  </el-card>
</template>

<style scoped lang="scss">

</style>